home *** CD-ROM | disk | FTP | other *** search
- /*
- * CSignedDataFile.c
- * Copyright © 1993 Apple Computer Inc.
- * All Rights Reserved
- *
- * This subclass to CDataFile performs file-level
- * Digital Signature processing according to the
- * following model:
- *
- * If the file has a signature, it will be checked
- * and a Failure condition raised if the signature
- * is not verified. If the signature verifies correctly,
- * the signer will be displayed in a Modal Dialog
- * window.
- *
- * To sign a file, your application should execute
- * myFile->SignFileOnClose(TRUE) before closing
- * the file. The signature will be appended when
- * the file is closed.
- *
- * Note that the actual signature is not accessable
- * to your application.
- */
-
- #include "CSignedDataFile.h"
- #include <Exceptions.h>
- #include <OCEErrors.h>
- #include <DigitalSignature.h>
-
- void
- CSignedDataFile::ISignedDataFile(void)
- {
- inherited::ISignature();
- }
-
- /*
- * SignFile is a soup-to-nuts signature handler. It signs
- * a complete, closed, file, handling context creation
- * if necessary. Note that it must be called as follows:
- * 1. Get the FSSpec for this file.
- * 2. Close the file (this deletes the CFile copy of
- * the FSSpec).
- * 3. SignFile.
- * 4. DisposeSignerContext()
- */
- void
- CSignedDataFile::SignFile(
- const FSSpec *signerFile,
- ConstStr255Param promptString,
- const FSSpec *dataFile,
- SIGStatusProcPtr statusProc
- )
- {
- OSErr status;
- Str255 msg;
- Size signatureSize;
-
- NewContext(kSIGSign);
- signatureSize = SignPrepare(signerFile, promptString);
- if (statusProc == gSIGStatusProc) {
- GetIndString(msg, STRn_SIGStatusProc, kStatusSignString);
- InitDefaultStatusProc(msg, dataFile->name);
- }
- status = SIGSignFile(
- gSIGContextPtr,
- signatureSize,
- dataFile,
- statusProc
- );
- DisposeDefaultStatusProc();
- if (status != noErr)
- DisposeSignerContext();
- FailOSErr(status);
- }
-
- /*
- * VerifyFile is a soup-to-nuts signature handler. It verifies
- * a named file. This must be called in the following sequence:
- * 1. Get the file name.
- * 2. Get the FSSpec associated with this file.
- * 4. Call the VerifyFile method.
- * 5. DisposeSignerContext.
- * 6. If successful, open the file read-only (it was
- * set read-only when the file was signed).
- */
- void
- CSignedDataFile::VerifyFile(
- const FSSpec *fileSpec,
- SIGStatusProcPtr statusProc
- )
- {
- OSErr status;
- Str255 msg;
-
- NewContext(kSIGVerify);
- if (statusProc == gSIGStatusProc) {
- GetIndString(msg, STRn_SIGStatusProc, kStatusVerifyString);
- InitDefaultStatusProc(msg, fileSpec->name);
- }
- status = SIGVerifyFile(
- gSIGContextPtr,
- fileSpec,
- statusProc
- );
- DisposeDefaultStatusProc();
- if (status != noErr
- && status != kSIGInvalidCredentialErr)
- DisposeSignerContext();
- FailOSErr(status);
- }
-
- Boolean
- CSignedDataFile::FileIsSigned(
- const FSSpec *fileSpec
- )
- {
- OSErr status;
- Boolean result;
-
- status = SIGFileIsSigned(fileSpec);
- switch (status) {
- case noErr:
- result = TRUE;
- break;
- case kSIGNoSignature:
- result = FALSE;
- break;
- default:
- FailOSErr(status);
- }
- return (result);
- }
-
-